/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef DEVICES_E22_H
#define DEVICES_E22_H


/* Includes ------------------------------------------------------------------*/
#include "Devices_E22_BaseConfig.h"
#include <stdint.h>
#include <stdio.h>
#include <string.h>

/* Exported constants --------------------------------------------------------*/
/* Using Grand unions */
#pragma anon_unions

#define Receiver_SenderMessageLength 12
#define E22_SettingMessageLength 12

/* RF433 Base Config */
#define RF433_ADDR        (1001)
#define RF433_CHANNEL     (40)
#define RF433_NETID       E22_DEFAULT
#define RF433_UART_BPS    E22_UART_115200
#define RF433_UART_CHK    E22_UART_8N1
#define RF433_RF_BPS      E22_RF_BPS_9K6
#define RF433_RF_PACK     E22_RF_PACK_240
#define RF433_RSSI_NOISE  E22_RSSI_NOISE_OFF
#define RF433_RF_PWR      E22_RF_PWR_30DBM
#if 1
    #define RF433_RSSI_BYTES  E22_RSSI_BYTES_OFF
#else
    #define RF433_RSSI_BYTES  E22_RSSI_BYTES_ON
#endif

#define RF433_TRAN        E22_TRAN_DIRECT
#define RF433_TRAN_RELAY  E22_TRAN_RELAY_OFF
#define RF433_LBT         E22_LBT_OFF
#define RF433_WOR         E22_WOR_SEND
#define RF433_WOR_PERIOD  E22_WOR_PERIOD_2000
#define RF433_CRYPT_H     E22_DEFAULT
#define RF433_CRYPT_L     E22_DEFAULT
#define RF433_START_ADDR  (0x00)
#define RF433_PACK_LEN    (0x09)


/* Exported macros -----------------------------------------------------------*/

#define RF433_CONFIG_PACK { \
						   (uint8_t)E22_CMD_HEAD, \
						   (uint8_t)RF433_START_ADDR, \
						   (uint8_t)RF433_PACK_LEN, \
						   (uint8_t)(RF433_ADDR >> 8)&0xff, \
						   (uint8_t)(RF433_ADDR)&0xff, \
						   (uint8_t)RF433_NETID, \
						   (uint8_t)((RF433_UART_BPS&0x07) << 5)|((RF433_UART_CHK&0x03) << 3)|(RF433_RF_BPS&0x07), \
						   (uint8_t)((RF433_RF_PACK&0x03) << 6)|(RF433_RSSI_NOISE << 5)|(RF433_RF_PWR&0x03), \
						   (uint8_t)RF433_CHANNEL % E22_CHANNEL_MAX, \
						   (uint8_t)(RF433_RSSI_BYTES << 7)|(RF433_TRAN << 6)|(RF433_TRAN_RELAY << 5)|(RF433_LBT << 4)|(RF433_WOR << 3)|(RF433_WOR_PERIOD&0x03), \
						   (uint8_t)RF433_CRYPT_H, \
						   (uint8_t)RF433_CRYPT_L, \
						  }

							
#define E22_FucGroundInit \
{ \
	&E22_RF_Setting, \
}


/* Exported types ------------------------------------------------------------*/
typedef struct
{
	union
	{
		uint8_t E22_SettingMessage[E22_SettingMessageLength];
		struct
		{
			uint8_t Header;
			uint8_t Start_Address;
			uint8_t PackageLength;
			uint8_t Address_L;
			uint8_t Address_H;
			uint8_t NetID;
			uint8_t UART_BSP_CHK_RF_BPS;
			uint8_t RF_PACK_RSSI_RF_PWR;
			uint8_t Channal;
			uint8_t RSSI_TRAN_LBT_WOR_PERIOD;
			uint8_t Crypt_H;
			uint8_t Crypt_L;
		};
	};
}E22_Setting_t;


typedef struct
{
	void(*E22_RF_Setting)(uint16_t Address,uint8_t Channel);
}E22_Fuc;


/* Exported variables --------------------------------------------------------*/
extern E22_Fuc E22_Function;


/* End -----------------------------------------------------------------------*/
#endif
